/**
 * Created by dbwyxl on 2017/9/19.
 */
module.exports =function($cookies,$scope, $rootScope, $state,$stateParams,caseSourcesService){

   $scope.billId=$stateParams.billId;
   $scope.serviceid=$stateParams.serviceid;
  //返回案源池
  $scope.skipBillBack=skipBillBack;
  // 获取接单详情
  $scope.getServiceDetail=getServiceDetail;
  //确认接单
  $scope.caseBillAffirm=caseBillAffirm;
  //下载附件
  $scope.sourcesFileProgress=sourcesFileProgress;
  $scope.businessListD=JSON.parse(sessionStorage.getItem('businessListD'));


  $scope.getServiceDetail();


  function getServiceDetail(){
    caseSourcesService.getServiceDetail($scope.billId,$scope.serviceid).then(function(data){
      if(data.code==1){
       $scope.caseBillDetail=data.data.detail[0];
       $scope.caseBillDetailF=data.data.file[0];
      }
    })
  }

  function caseBillAffirm() {
    bootbox.dialog({
      message: "确定要接单？",
      title: "提示信息",
      className:'d-promptBox',
      buttons: {
        OK: {
          label: "确定",
          className: "d-btn-confirm",
          callback: function () {
            caseSourcesService.takeService($scope.billId).then(function (data) {
              if (data.code == 1) {
                $state.go('orderReceivingDetails', {id: data.id})
              }
            })
          }
        },
        Cancel: {
          label: "取消",
          className: "d-btn-cancel",
          callback: function () {
          }
        }
      }
    });
  }
  function sourcesFileProgress (fileX) {
    caseSourcesService.servicecaseFileDownload(fileX.casesourceid).then(function (response) {
      var fileData = new Blob([response]);
      var link = document.createElement('a');
      link.href = URL.createObjectURL(fileData);
      link.download = fileX.attrfilename;
      link.click();
    });
  }


  function skipBillBack (){
    $state.go('caseSources')
  }
  //
};
